{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib\n",
    "import numpy\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "matplotlib.style.use('ggplot')\n",
    "matplotlib.rcParams.update({'font.size': 12})\n",
    "matplotlib.rcParams.update({'xtick.labelsize': 'x-large'})\n",
    "matplotlib.rcParams.update({'xtick.major.size': '0'})\n",
    "matplotlib.rcParams.update({'ytick.labelsize': 'x-large'})\n",
    "matplotlib.rcParams.update({'ytick.major.size': '0'})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://stackoverflow.com/questions/18386210/annotating-ranges-of-data-in-matplotlib\n",
    "def draw_brace(ax, xspan, yoffset, text):\n",
    "    \"\"\"Draws an annotated brace on the axes.\"\"\"\n",
    "    xmin, xmax = xspan\n",
    "    xspan = xmax - xmin\n",
    "    ax_xmin, ax_xmax = ax.get_xlim()\n",
    "    xax_span = ax_xmax - ax_xmin\n",
    "    ymin, ymax = ax.get_ylim()\n",
    "    yspan = ymax - ymin\n",
    "    resolution = int(xspan/xax_span*100)*2+1 # guaranteed uneven\n",
    "    beta = 300./xax_span # the higher this is, the smaller the radius\n",
    "\n",
    "    x = numpy.linspace(xmin, xmax, resolution)\n",
    "    x_half = x[:int(resolution/2+1)]\n",
    "    y_half_brace = (1/(1.+numpy.exp(-beta*(x_half-x_half[0])))\n",
    "                    + 1/(1.+numpy.exp(-beta*(x_half-x_half[-1]))))\n",
    "    y = numpy.concatenate((y_half_brace, y_half_brace[-2::-1]))\n",
    "    y = yoffset + (.05*y - .02)*yspan # adjust vertical position\n",
    "\n",
    "    ax.autoscale(False)\n",
    "    ax.plot(x, y, color='black', lw=1)\n",
    "\n",
    "    ax.text((xmax+xmin)/2., yoffset+.07*yspan, text, ha='center', va='bottom', fontdict={'family': 'monospace'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Ramp\n",
    "A = 2\n",
    "B = 8\n",
    "t_start = 10\n",
    "t_ramp = 20\n",
    "t_end = 30\n",
    "\n",
    "x = [0, t_start, t_start+t_ramp, t_start+t_ramp+t_end]\n",
    "y = [A, A, B, B]\n",
    "\n",
    "fig = matplotlib.figure.Figure(figsize=(7, 4.32624056), dpi=100)\n",
    "ax = fig.add_subplot()\n",
    "ax.plot(x,y)\n",
    "ax.set_ylim(0,10)\n",
    "ax.set_xlim(0,50)\n",
    "ax.set_xlabel('step')\n",
    "ax.set_ylabel('value')\n",
    "ax.set_xticks([10, 20, 30, 40])\n",
    "ax.set_xticklabels(['']*4)\n",
    "ax.set_yticks([2,4,6,8,10])\n",
    "ax.set_yticklabels(['A', '', '', 'B', ''])\n",
    "draw_brace(ax, (0,t_start), A, \"t_start\")\n",
    "draw_brace(ax, (t_start,t_start+t_ramp), B, \"t_ramp\")\n",
    "fig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig.savefig('../variant-ramp.svg', bbox_inches='tight', facecolor=(1, 1, 1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Cycle\n",
    "A = 2\n",
    "B = 8\n",
    "t_start = 10\n",
    "t_A = 9\n",
    "t_AB = 4\n",
    "t_B = 5\n",
    "t_BA = 7\n",
    "\n",
    "x_in = [0, t_start, t_A, t_AB, t_B, t_BA, t_A, t_AB, t_B, t_BA, t_A, t_AB]\n",
    "x = numpy.cumsum(x_in)\n",
    "y = [A, A, A, B, B, A, A, B, B, A, A, B]\n",
    "\n",
    "fig = matplotlib.figure.Figure(figsize=(7, 4.32624056), dpi=100)\n",
    "ax = fig.add_subplot()\n",
    "ax.plot(x,y)\n",
    "ax.set_ylim(0,10)\n",
    "ax.set_xlim(0,60)\n",
    "ax.set_xlabel('step')\n",
    "ax.set_ylabel('value')\n",
    "ax.set_xticks([10, 20, 30, 40, 50])\n",
    "ax.set_xticklabels(['']*5)\n",
    "ax.set_yticks([2,4,6,8,10])\n",
    "ax.set_yticklabels(['A', '', '', 'B', ''])\n",
    "draw_brace(ax, (0,t_start), A, \"t_start\")\n",
    "draw_brace(ax, (t_start,t_start+t_A), A, \"t_A\")\n",
    "draw_brace(ax, (t_start+t_A,t_start+t_A+t_AB), B, \"t_AB\")\n",
    "draw_brace(ax, (t_start+t_A+t_AB,t_start+t_A+t_AB+t_B), B, \"t_B\")\n",
    "draw_brace(ax, (t_start+t_A+t_AB+t_B,t_start+t_A+t_AB+t_B+t_BA), B, \"t_BA\")\n",
    "fig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig.savefig('../variant-cycle.svg', bbox_inches='tight', facecolor=(1, 1, 1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def power_func(init, final, power, start, length):\n",
    "    def var(timestep):\n",
    "        if timestep < start:\n",
    "            return init\n",
    "        elif timestep < start + length:\n",
    "            inv_a, inv_b = (init ** (1 / power)), (final ** (1 / power))\n",
    "            frac = (timestep - start) / length\n",
    "            return ((inv_b * frac) + ((1 - frac) * inv_a)) ** power\n",
    "        else:\n",
    "            return final\n",
    "    return var"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Power\n",
    "A = 2\n",
    "B = 8\n",
    "power = 1 / 10\n",
    "t_start = 10 \n",
    "t_size = 20\n",
    "t_end = 20\n",
    "\n",
    "x = numpy.linspace(0, t_start + t_size + t_end, 100)\n",
    "y = list(map(power_func(A, B, power, t_start, t_size), x))\n",
    "\n",
    "fig = matplotlib.figure.Figure(figsize=(7, 4.32624056), dpi=100)\n",
    "ax = fig.add_subplot()\n",
    "ax.plot(x,y)\n",
    "ax.set_ylim(0,10)\n",
    "ax.set_xlim(0,50)\n",
    "ax.set_xlabel('step')\n",
    "ax.set_ylabel('value')\n",
    "ax.set_xticks([10, 20, 30, 40])\n",
    "ax.set_xticklabels(['']*4)\n",
    "ax.set_yticks([2,4,6,8,10])\n",
    "ax.set_yticklabels(['A', '', '', 'B', ''])\n",
    "draw_brace(ax, (0,t_start), A, \"t_start\")\n",
    "draw_brace(ax, (t_start,t_start+t_size), B, \"t_size\")\n",
    "fig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig.savefig('../variant-power.svg', bbox_inches='tight', facecolor=(1, 1, 1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
